//
//  MyViewController.m
//  XXX
//
//  Created by Xiaoshiheng_pro on 2017/2/20.
//  Copyright © 2017年 Xiaoshiheng_pro. All rights reserved.
//

#import "MyViewController.h"

@interface MyViewController ()

@end

@implementation MyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/**
 * 每次发送的data为两部分
 * header 内容数据的字节长度
 * body 内容数据
 */
- (NSData *)prepareData:(NSData *)data  type:(NSString *)type
{
    
    
    NSMutableDictionary * Dicdata=[NSMutableDictionary dictionaryWithObjectsAndKeys:type,@"type",data,@"data",nil];
    NSData *jsonData = [NSKeyedArchiver archivedDataWithRootObject:Dicdata];
    
    NSUInteger length = [jsonData length];
    NSMutableData *sendingData = [[NSMutableData alloc] init];
    [sendingData appendBytes:&length length:sizeof(NSUInteger)];
    [sendingData appendData:jsonData];
    
    return sendingData;
}

@end
